<?php
	include "include/common.inc.php";

	$errorMsg = "";
	
	if(isset($_POST["Register"]) and $_POST["Register"]){
	
	//echo "<h1>Thank you for registration!</h1>";
		$user = User::getUserByEmail($_POST["email"]);
		$u=User::getUserByUsername($_POST["username"]);
		
		if($_POST["username"]=="")
			$errorMsg="Enter User Name Please!";
		else if($_POST["email"]=="")
			$errorMsg="Enter Email Address Please!";
		else if($_POST["password"]=="")
			$errorMsg="Enter Password Please!";
			
			else if($_POST["password"]!=$_POST["CPassword"])
			$errorMsg="Password not consistent!";
			
		else if($user->getValue("id") != -1||$u->getValue("id") != -1)
			$errorMsg = "User Existed!";
		else{	
			$city = City::getCity(addslashes($_POST["country"]), addslashes($_POST["state"]));
		
			$user = new User(array(
					"type" => 2,
					"firstName" => $_POST["firstname"],
					"lastName" => $_POST["lastname"],
					"userName" => $_POST["username"],
					"gender" => $_POST["gender"],
					"email" => $_POST["email"],
					"password" => password($_POST["password"]),
					"birthday" => storeDate($_POST["birthday"]),
					"cityId" => $city->getValue("id")
			));
			$user->insert();
			processLogin($user);
			goToUrl("index.php");
		}
	}
?>

<!DOCTYPE html>
<!-- saved from url=(0040)http://getbootstrap.com/examples/signin/ -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<!--link rel="shortcut icon" href="http://getbootstrap.com/assets/ico/favicon.ico"-->
<title>Blind Dating</title>
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon">
<!-- Bootstrap core CSS -->
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://getbootstrap.com/examples/signin/signin.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy this line! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
		  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
		  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
		<![endif]-->
<style>
table, th, td
{
border:none;
border-collapse:collapse;
padding:8px;
}
table
{
width:350px;
border-spacing:30px;
}
body { padding-top: 50px; }
</style>
<script type= "text/javascript" src = "js/countries2.js"></script>

</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
      <a class="navbar-brand" href="index.php">NUS Blind Dating Site</a>
    </div>
	<ul class="nav navbar-nav">
        <li><a href="index.php">Home</a></li>
        <li><a href="Login.php">Login</a></li>
		<li><a href="Register.php">Register</a></li>
	</ul>
	</div>
	
</nav>


<div class="container" align="center">
<div class="error"> <h2><?php echo $errorMsg; ?></h2></div>
  <h2 class="form-signin-heading">Please Register!</h2>
  <form action="" method ="post" name="register",class="form-signin" role="form" >
    <table>
	<tr>
        <td><label>FirstName</label></td>
        <td><input type="text" class="form-control" placeholder="FirstName" required="" autofocus="" name="firstname"></td>
      </tr>
	  <tr>
        <td><label>LastName</label></td>
        <td><input type="text" class="form-control" placeholder="LastName" required="" autofocus="" name="lastname"></td>
      </tr>
	<tr>
        <td><label>UserName</label></td>
        <td><input type="text" class="form-control" placeholder="UserName" required="" autofocus="" name="username"></td>
      </tr>
	  <tr>
        <td><label>Gender</label></td>
        <td>
		<select name="gender" class="form-control" required="" autofocus="">
		<option value="Male"> Male</option>
		<option value="Female"> Female</option>
		</select>
		</td>
      </tr>
      <tr>
        <td><label>Email</label></td>
        <td><input type="email" class="form-control" placeholder="Email address" required="" autofocus="" name="email"></td>
      </tr>
	  
	  <tr>
        <td><label>Nation</label></td>
        <td><select class="form-control"  onChange="print_state('state',this.value);" id="country" name = "country"></select></td>
      </tr>
	  <tr>
	  <td><label>State</label></td>
	  <td><select class="form-control" name ="state" id = "state" ></select>
<script language="javascript">print_country("country","Singapore");</script>
<script language="javascript">print_state("state","Singapore","Singapore");</script>
</td>
	  </tr>
	  <tr>
	  <td><label> Birthday</label> </td>
	  <td><input type="date" class="form-control" placeholder="Birthday"  autofocus="" name="birthday"></td>
	  </tr>
	  
      <tr>
	    <td><label>Password</label></td>
        <td><input type="password" class="form-control" placeholder="Password" required="" name="password"></td>
      </tr>
	  <tr>
	    <td><label>Confirmed Password</label></td>
        <td><input type="password" class="form-control" placeholder="Confirmed Password" required="" name="CPassword" ></td>
      </tr>

	  <tr>
      <td width= "50%" align= "left"> <button class="btn btn-lg btn-primary btn-block" type="submit" name="Register" value="Register">Register</button></td>
      <td width ="50%" align="right"> <button class="btn btn-lg btn-primary btn-block" type="submit" name="Reset" value="Reset">Reset</button></td>
	  <tr>
    </table>
  </form>
</div>
<!-- Bootstrap core JavaScript
		================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
</body>
</html>